package com.jackrain.nea.fc.dl.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OmsDlShareStockMapper {

    //查询所有的共享库存数据
    @Select("SELECT  " +
            "CP_C_STORE_ECODE AS CP_C_STORE_ECODE, " +
            "QTY_STOCK AS QTY_STOCK_ABLE, " +
            "PS_C_SKU_ECODE AS PS_C_SKU_ECODE, " +
            "MODIFIEDDATE AS MODIFIEDDATE " +
            "FROM DL_C_SHARESTOCK WHERE ISACTIVE='Y'")
    List<HashMap> selectDlShareStock();

    @SelectProvider(type = ViewScStockSql.class, method = "selectDlShareStockChange")
    List<HashMap> selectDlShareStockChange(@Param("id") Object[] id);

    class ViewScStockSql {
        public String selectDlShareStockChange(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("CP_C_STORE_ECODE AS CP_C_STORE_ECODE, " +
                            "QTY_STOCK AS QTY_STOCK_ABLE, " +
                            "PS_C_SKU_ECODE AS PS_C_SKU_ECODE, " +
                            "MODIFIEDDATE AS MODIFIEDDATE  ");
                    FROM("DL_C_SHARESTOCK");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }
    }


}
